layui.use(['form', 'layer', 'laydate', 'element'], function() {
	var form = layui.form();
	var $ = layui.jquery;
	var laydate = layui.laydate;
	var element = layui.element();
	$.ajax({
		type:"GET",
		url:url +'/ic-iot/devices/'+deviceId+'/settings',
		async:true,
		dataType : 'json',
		async:false,
		beforeSend: function(request) {
            request.setRequestHeader("accessToken", accessToken);
        },
		success : function(data) {
			if(data['code'] == 1){
				if(data.result.backlightAlarmFlag == 1){
					$("#onbacklightAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offbacklightAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.buzzerAlarmFlag == 1){
					$("#onbuzzerAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offbuzzerAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerOffAlarmFlag == 1){
					$("#onpowerOffAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerOffAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerOffBacklightAlarmFlag == 1){
					$("#onpowerOffBacklightAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerOffBacklightAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerOffBuzzerAlarmFlag == 1){
					$("#onpowerOffBuzzerAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerOffBuzzerAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerLowAlarmFlag == 1){
					$("#onpowerLowAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerLowAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerLowBacklightAlarmFlag == 1){
					$("#onpowerLowBacklightAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerLowBacklightAlarmFlag").attr('checked','checked');
					form.render();
				};
				if(data.result.powerLowBuzzerAlarmFlag == 1){
					$("#onpowerLowBuzzerAlarmFlag").attr('checked','checked');
					form.render();
				}else{
					$("#offpowerLowBuzzerAlarmFlag").attr('checked','checked');
					form.render();
				};
				$("#deviceName").text(data.result.deviceName);
				$("#powerMix").val(data.result.powerMix);
				$("#alarmDifferenceCh2").val(data.result.alarmDifferenceCh2);
				$("#temMinCh1").val(data.result.temMinCh1);
				$("#temMaxCh1").val(data.result.temMaxCh1);
				$("#step").val(data.result.dataStep);
				$("#temMinCh2").val(data.result.temMinCh2);
				$("#temMaxCh2").val(data.result.temMaxCh2);
				$("#alarmDifferenceCh1").val(data.result.alarmDifferenceCh1);
				$("#deviceId").val(data.result.deviceId);
				$("#alarmDataStep").val(data.result.alarmDataStep);
				$("#locationStep").val(data.result.locationStep);
			}else{
				ifajax(data);
			}
		}
	});
	$("#btn-adduser").click(function(){
		var data = formToJson($("#form-three"));
		debugger;
		var deviceId = $("#deviceId").val();
		$.ajax({
			type:"put",
			url: url +'/ic-iot/users/'+adminId+'/devices/'+deviceId+'/setting',
			data:data,
			dataType : 'json',
			async:false,
			contentType: "application/json; charset=utf-8",
			beforeSend: function(request) {
	            request.setRequestHeader("accessToken", accessToken);
	        },
			success : function(data) {
				if(data['code'] == 1){
					layer.msg(data['description']);
				}else{
					ifajax(data);
				}
			}
		});
	});
	
 
});
